package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.MaterialMapper;
import com.qidian.mes.defect.service.MaterialService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.pojo.DetectName;
import com.qidianit.mes.pojo.MaterialDetect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-23 0:25
 */
@Service
public class MaterialServiceImpl implements MaterialService {
    @Autowired
    private MaterialMapper materialMapper;


    @Override
    public MESResult list(String materialId, String materialName, String model, Long testLow, String unit, String numberTop, Long fatal, Long severe, Long slight, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<MaterialDetect> materialDetects = materialMapper.selectList(materialId,materialName,model,testLow,unit,numberTop,fatal,severe,slight);
        PageInfo<MaterialDetect> pageInfo = new PageInfo<>(materialDetects);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);

    }

    @Override
    public MESResult save(MaterialDetect materialDetect) {
        return materialMapper.insert(materialDetect) == 1?MESResult.success():MESResult.error();
    }

    @Override
    public MESResult update(MaterialDetect materialDetect) {
        return MESResult.success(200,"ok",materialMapper.update(materialDetect));

    }

    @Override
    public MESResult selectById(String materialId) {
        return MESResult.success(materialMapper.selectById(materialId));
    }


}
